<HTML><HEAD><TITLE>Hub</TITLE></HEAD>
<BODY>
<!#CLASSDEF
Hub
#ENDCLASSDEF>
<H1>Hub</H1>

<P>The Hub is the equivalent of the ORB - a central context for everything in
the distributed object system.  
<P>The Hub has a <B>registry</B> which can be as simple as a dictionary or as
sophisticated as a CORBA NamingContext.  It must provide the
<U></U>getitem<U></U> and <U></U>setitem<U></U> methods to dereference and
assign keys to objects.  
<H2>Methods</H2>
<UL>
<LI><A HREF="#__clearContext(self)">__clearContext(self)</A>
<LI><A HREF="#__connectionClosed(self,_protoId,_protoInfo)">__connectionClosed(self, protoId, protoInfo)</A>
<LI><A HREF="#__execInputLine(self)">__execInputLine(self)</A>
<LI><A HREF="#__getAllProtocols(self)">__getAllProtocols(self)</A>
<LI><A HREF="#__getObject(self,_node,_splitKey)">__getObject(self, node, splitKey)</A>
<LI><A HREF="#__getSelectors(self,_servers,_rd,_wr,_er)">__getSelectors(self, servers, rd, wr, er)</A>
<LI><A HREF="#__init__(self,_registry,_threadMode)">__init__(self, registry, threadMode)</A>
<LI><A HREF="#__needSelectThread(self)">__needSelectThread(self)</A>
<LI><A HREF="#__processRequest(self,_request,_protocol)">__processRequest(self, request, protocol)</A>
<LI><A HREF="#__selectLoop(self,_msgId)">__selectLoop(self, msgId)</A>
<LI><A HREF="#__serviceClient(self,_clientConnection)">__serviceClient(self, clientConnection)</A>
<LI><A HREF="#__serviceConnections(self,_server)">__serviceConnections(self, server)</A>
<LI><A HREF="#__serviceFunction(self,_clientConnection,_request)">__serviceFunction(self, clientConnection, request)</A>
<LI><A HREF="#__setContext(self,_context)">__setContext(self, context)</A>
<LI><A HREF="#_getResponse(self,_responseId)">_getResponse(self, responseId)</A>
<LI><A HREF="#addObject(self,_key,_object)">addObject(self, key, object)</A>
<LI><A HREF="#addProtocol(self,_proto)">addProtocol(self, proto)</A>
<LI><A HREF="#addReactor(self,_reactor)">addReactor(self, reactor)</A>
<LI><A HREF="#addServer(self,_server)">addServer(self, server)</A>
<LI><A HREF="#getContext(self)">getContext(self)</A>
<LI><A HREF="#getObject(self,_fullKey)">getObject(self, fullKey)</A>
<LI><A HREF="#getProtocol(self,_protoId)">getProtocol(self, protoId)</A>
<LI><A HREF="#getRemoteObject(self,_key,_remoteFactory)">getRemoteObject(self, key, remoteFactory)</A>
<LI><A HREF="#getThreadMode(self)">getThreadMode(self)</A>
<LI><A HREF="#isThreaded(self)">isThreaded(self)</A>
<LI><A HREF="#mainloop(self)">mainloop(self)</A>
<LI><A HREF="#makeAnonObject(self,_object,_remoteFactory)">makeAnonObject(self, object, remoteFactory)</A>
<LI><A HREF="#makeRemoteObject(self,_objectId,_remoteFactory)">makeRemoteObject(self, objectId, remoteFactory)</A>
<LI><A HREF="#processRequest(self,_request)">processRequest(self, request)</A>
<LI><A HREF="#removeObject(self,_key)">removeObject(self, key)</A>
</UL>
<A NAME="__clearContext">
<A NAME="__clearContext(self)">
<H3>__clearContext(self)</H3>
<PRE>
   def __clearContext(self):
</PRE>

<A NAME="__connectionClosed">
<A NAME="__connectionClosed(self,_protoId,_protoInfo)">
<H3>__connectionClosed(self, protoId, protoInfo)</H3>
<PRE>
   def __connectionClosed(self, protoId, protoInfo):
</PRE>

<P>Called when a connection is closed.  
<A NAME="__execInputLine">
<A NAME="__execInputLine(self)">
<H3>__execInputLine(self)</H3>
<PRE>
   def __execInputLine(self):
</PRE>

<A NAME="__getAllProtocols">
<A NAME="__getAllProtocols(self)">
<H3>__getAllProtocols(self)</H3>
<PRE>
   def __getAllProtocols(self):
</PRE>

<P>Internal method to return all <A HREF="Protocol.html"> Protocol</A> objects
as a list.  
<A NAME="__getObject">
<A NAME="__getObject(self,_node,_splitKey)">
<H3>__getObject(self, node, splitKey)</H3>
<PRE>
   def __getObject(self, node, splitKey):
</PRE>

<P>Private version of <A HREF="#getObject"> getObject()</A>, in which
<I>splitKey</I> is a list.  
<A NAME="__getSelectors">
<A NAME="__getSelectors(self,_servers,_rd,_wr,_er)">
<H3>__getSelectors(self, servers, rd, wr, er)</H3>
<PRE>
   def __getSelectors(self, servers, rd, wr, er):
</PRE>

<P>Creates lists of objects for the select lists.  
<P>parms: 
<DL> <DT> servers 
<DD> 
<P>[list&lt;ProtocolServer&gt;] list of servers <P>

</DL>

<A NAME="__init__">
<A NAME="__init__(self,_registry,_threadMode)">
<H3>__init__(self, registry, threadMode)</H3>
<PRE>
   def __init__(self, registry, 
                threadMode = _haveThreads and THRD_FUNC or THRD_NONE
                ):
</PRE>

<A NAME="__needSelectThread">
<A NAME="__needSelectThread(self)">
<H3>__needSelectThread(self)</H3>
<PRE>
   def __needSelectThread(self):
</PRE>

<A NAME="__processRequest">
<A NAME="__processRequest(self,_request,_protocol)">
<H3>__processRequest(self, request, protocol)</H3>
<PRE>
   def __processRequest(self, request, protocol):
</PRE>

<A NAME="__selectLoop">
<A NAME="__selectLoop(self,_msgId)">
<H3>__selectLoop(self, msgId)</H3>
<PRE>
   def __selectLoop(self, msgId = None):
</PRE>

<A NAME="__serviceClient">
<A NAME="__serviceClient(self,_clientConnection)">
<H3>__serviceClient(self, clientConnection)</H3>
<PRE>
   def __serviceClient(self, clientConnection):
</PRE>

<A NAME="__serviceConnections">
<A NAME="__serviceConnections(self,_server)">
<H3>__serviceConnections(self, server)</H3>
<PRE>
   def __serviceConnections(self, server):
</PRE>

<P>This is executed in a thread to begin servicing client connections for a
particular server.  
<A NAME="__serviceFunction">
<A NAME="__serviceFunction(self,_clientConnection,_request)">
<H3>__serviceFunction(self, clientConnection, request)</H3>
<PRE>
   def __serviceFunction(self, clientConnection, request):
</PRE>

<A NAME="__setContext">
<A NAME="__setContext(self,_context)">
<H3>__setContext(self, context)</H3>
<PRE>
   def __setContext(self, context):
</PRE>

<A NAME="_getResponse">
<A NAME="_getResponse(self,_responseId)">
<H3>_getResponse(self, responseId)</H3>
<PRE>
   def _getResponse(self, responseId):
</PRE>

<P>This function reenters the message processing loop and waits for a particular
response.  
<P>If any response other that response should be received, a <A
HREF="/BadResponse_index.html"> BadResponse</A> exception will be raised.  
<A NAME="addObject">
<A NAME="addObject(self,_key,_object)">
<H3>addObject(self, key, object)</H3>
<PRE>
   def addObject(self, key, object):
</PRE>

<P>Registers the <I>object</I> as a remote object under the name <I>key</I> (a
string).  Any kind of object can be registered.  
<P>Note that a key consisting of name parts seperated by forward slashes can be
used, but it does not produce the results that one might expect after reading
the documentation on <A HREF="#getObject"> getObject()</A> - i.e.  the object is
not stored in a nested context.  
<A NAME="addProtocol">
<A NAME="addProtocol(self,_proto)">
<H3>addProtocol(self, proto)</H3>
<PRE>
   def addProtocol(self, proto):
</PRE>

<P>This function should generally be called by the protocol constructor to
register itself with the hub.  
<A NAME="addReactor">
<A NAME="addReactor(self,_reactor)">
<H3>addReactor(self, reactor)</H3>
<PRE>
   def addReactor(self, reactor):
</PRE>

<P>Adds a new reactor object to the hub's internal list.  This will cause the
reactor to be included in the select loop.  
<P>parms: 
<DL> <DT> reactor 
<DD> 
<P>[<A HREF="Reactor.html"> Reactor</A>] <P>

</DL>

<A NAME="addServer">
<A NAME="addServer(self,_server)">
<H3>addServer(self, server)</H3>
<PRE>
   def addServer(self, server):
</PRE>

<P>Registers <I>server</I> (an instance of ProtocolServer).  In threaded
communication mode, the hub will begin handling connections on the server in
another thread.  
<A NAME="getContext">
<A NAME="getContext(self)">
<H3>getContext(self)</H3>
<PRE>
   def getContext(self):
</PRE>

<P>Returns the current context object.  This is only available from within a
remote method call.  If it is called from somewhere other than a remotely
invoked method, <B>None</B> is returned.  
<A NAME="getObject">
<A NAME="getObject(self,_fullKey)">
<H3>getObject(self, fullKey)</H3>
<PRE>
   def getObject(self, fullKey):
</PRE>

<P>Returns the object (the object that was added using <TT>addObject()</TT>, not
necessarily a <A HREF="RemoteObject.html"> RemoteObject</A>) associated with
<I>fullKey</I>.  
<P> <I>fullKey</I> can resemble a UNIX path - that is, it can consist of name
components seperated by forward slashes.  If it is, and there is nothing
matching the key in the registry, a recursive retrieval is performed.  
<A NAME="getProtocol">
<A NAME="getProtocol(self,_protoId)">
<H3>getProtocol(self, protoId)</H3>
<PRE>
   def getProtocol(self, protoId):
</PRE>

<P>This is used to get or create a protocol from its id.  Returns the protocol
if it already exists, creates it if it doesn't.  
<A NAME="getRemoteObject">
<A NAME="getRemoteObject(self,_key,_remoteFactory)">
<H3>getRemoteObject(self, key, remoteFactory)</H3>
<PRE>
   def getRemoteObject(self, key, remoteFactory = None):
</PRE>

<P>Returns a remote object for an object that has been added to the current hub
identified by <I>key</I>.  
<P>parms: 
<DL> <DT> key 
<DD> 
<P>[string] object key <P>
<DT> remoteFactory 
<DD> 
<P>[<A HREF="RemoteObjectFactory.html"> RemoteObjectFactory</A> or None] if
present, this is the remote object factory used to create the remote object.  If
not, <A HREF="DynamicRemoteObjectFactory.html"> DynamicRemoteObjectFactory</A>
is used.  <P>

</DL>

<A NAME="getThreadMode">
<A NAME="getThreadMode(self)">
<H3>getThreadMode(self)</H3>
<PRE>
   def getThreadMode(self):
</PRE>

<P>Returns the hub's thread mode.  Thread modes are: 
<DL> <DT> <B> THRD_NONE</B> (0) 
<DD> 
<P>no threading <P>
<DT> <B> THRD_SELECT</B> (1) 
<DD> 
<P>run "select()" loop in a background thread <P>
<DT> <B> THRD_FUNC</B> (2) 
<DD> 
<P>Like <B> THRD_SELECT</B> but also create new threads for method invocations <P>
<DT> <B> THRD_COM</B> (3) 
<DD> 
<P>Create a listening thread for each Protocol and ServerProtocol and each
method invocation.  <P>

</DL>

<A NAME="isThreaded">
<A NAME="isThreaded(self)">
<H3>isThreaded(self)</H3>
<PRE>
   def isThreaded(self):
</PRE>

<P>Returns true if the hub is threaded, false if not.  The hub is threaded in
all threads modes except <B> THRD_NONE</B> 
<A NAME="mainloop">
<A NAME="mainloop(self)">
<H3>mainloop(self)</H3>
<PRE>
   def mainloop(self):
</PRE>

<A NAME="makeAnonObject">
<A NAME="makeAnonObject(self,_object,_remoteFactory)">
<H3>makeAnonObject(self, object, remoteFactory)</H3>
<PRE>
   def makeAnonObject(self, object, remoteFactory = None):
</PRE>

<P>Makes <I>object</I> into an anonymous remote object.  Returns an instance of
a <A HREF="RemoteObject.html"> RemoteObject</A> derivative for the object.  
<P>Anonymous remote objects are remote objects that are registered without any
particular key - presumably for temporary use.  Actually, the key is the
object's <B>id</B> - the address of the object.  
<P>If <I>remoteFactory</I> is supplied, it should be an instance of a class
derived from <A HREF="RemoteObjectFactory.html"> RemoteObjectFactory</A>.  If it
is not supplied, <A HREF="DynamicRemoteObjectFactory.html">
DynamicRemoteObjectFactory</A> is used to create and return a <A
HREF="DynamicRemoteObject.html"> DynamicRemoteObject</A>.  
<A NAME="makeRemoteObject">
<A NAME="makeRemoteObject(self,_objectId,_remoteFactory)">
<H3>makeRemoteObject(self, objectId, remoteFactory)</H3>
<PRE>
   def makeRemoteObject(self, objectId, remoteFactory = None):
</PRE>

<P>Returns a remote object for the given object id.  An object id consists of a
protocol id followed by a colon and the object key.  
<P>If <I>remoteFactory</I> is supplied, it should be an instance of a class
derived from <A HREF="RemoteObjectFactory.html"> RemoteObjectFactory</A>.  If it
is not supplied, <A HREF="DynamicRemoteObjectFactory.html">
DynamicRemoteObjectFactory</A> is used to create and return a <A
HREF="DynamicRemoteObject.html"> DynamicRemoteObject</A>.  
<A NAME="processRequest">
<A NAME="processRequest(self,_request)">
<H3>processRequest(self, request)</H3>
<PRE>
   def processRequest(self, request):
</PRE>

<P>Processes a request (an instance of <A HREF="Request.html"> Request</A>) and
returns the response (a <A HREF="Response.html"> Response</A>).  
<A NAME="removeObject">
<A NAME="removeObject(self,_key)">
<H3>removeObject(self, key)</H3>
<PRE>
   def removeObject(self, key):
</PRE>

<P>Deregisters the object listed under the given <I>key</I>.  
<P>parms: 
<DL> <DT> key 
<DD> 
<P>[string] object key.  <P>

</DL>

</BODY></HTML>
